<?php
namespace app\index\controller;

use app\common\controller\HomeBase;
use app\common\model\Imgcategory as CategoryModel;
use app\common\model\Images as ImagesModel;
use think\Session;

class ImgList extends HomeBase
{
    protected $images_model;
    protected $category_model;

    public function _initialize(){
        parent::_initialize();
        $this->category_model = new CategoryModel();
        $this->images_model = new ImagesModel();
        $category_level_list  = $this->category_model->getLevelList();
        $erji = $this->category_model->where('pid','neq','0')->select();
        $this->assign('erjicategory_level_list', $erji);
        $this->assign('imgcategory_level_list', $category_level_list);
        $this->assign('title','素材库列表');        
    }

    public function index_bk(){
        $result = $this->images_model
                    ->order('id desc')
                    ->select();
        $this->assign('img_list',$result);
        return $this->fetch();
    }

    public function img_detail($id){
        $index_id = session::get('index_id');
        if($index_id){
            $list = $this->images_model->where('pid',$id)->column('path');
        }else{
            $list = $this->images_model->where('pid',$id)->column('thumb');
        }
        $this->assign('list',$list);
        return $this->fetch();
    }

    public function index(){
        $result = $this->images_model
            ->order('id desc')
            ->select();
        $this->assign('img_list',$result);
        return $this->fetch();
    }
}